import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter04/pages/tabs/category.dart';
import 'package:flutter04/pages/tabs/explore.dart';
import 'package:flutter04/pages/tabs/home.dart';
import 'package:flutter04/pages/tabs/message.dart';
import 'package:flutter04/pages/tabs/my.dart';

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, this.title = "Flutter App Page"});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _currentIndex = 0;
  final List<Widget> _pages = const [
    HomePage(),
    CategoryPage(),
    MessagePage(),
    ExplorePage(),
    MyPage()
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        foregroundColor: Colors.white,
        centerTitle: true,
        title: Text(
          widget.title,
        ),
      ),
      drawer: Drawer(
        child: ListView(
          children: [
            UserAccountsDrawerHeader(
              accountName: const Text("兰陵王"),
              accountEmail: const Text("gemiman@sina.com"),
              currentAccountPicture: const CircleAvatar(
                backgroundImage: NetworkImage(
                    "https://fs.aihujiankang.com/3cafa85e15da73f8da0f70c1bd2a7f24712fae5c3999d281bb05f802f7c3b0a8.jpg"),
              ),
              otherAccountsPictures: [
                Image.network(
                    "https://fs.aihujiankang.com/8c9718e0c5f3a3afce870425ad842852c0e897d27c0c819d3452eea8f8dbaaf9.jpg"),
                Image.network(
                    "https://fs.aihujiankang.com/871e492e578d2f96c6b1f3e17b75aa0a873a5bc0c35fc569b157734a6f5f9d6e.jpg"),
                Image.network("https://fs.aihujiankang.com/ding@3x.png"),
              ],
              decoration: BoxDecoration(
                  color: Theme.of(context).colorScheme.inversePrimary,
                  image: const DecorationImage(
                    fit: BoxFit.cover,
                    image:
                        NetworkImage("https://fs.aihujiankang.com/nav-top.png"),
                  )),
            ),
            const ListTile(
              leading: CircleAvatar(
                child: Icon(Icons.people),
              ),
              title: Text("个人中心"),
            ),
            const Divider(),
            const ListTile(
              leading: CircleAvatar(
                child: Icon(Icons.settings),
              ),
              title: Text("系统设置"),
            ),
            const Divider(),
          ],
        ),
      ),
      endDrawer: const Drawer(
        child: Text("右侧侧边栏"),
      ),
      body: _pages[_currentIndex],
      bottomNavigationBar: BottomNavigationBar(
        iconSize: 35,
        fixedColor: Colors.red,
        unselectedItemColor: Theme.of(context).colorScheme.inversePrimary,
        type: BottomNavigationBarType.fixed,
        currentIndex: _currentIndex,
        onTap: (idx) {
          if (kDebugMode) {
            print(idx);
          }
          setState(() {
            _currentIndex = idx;
          });
        },
        items: const [
          BottomNavigationBarItem(icon: Icon(Icons.home), label: "首页"),
          BottomNavigationBarItem(icon: Icon(Icons.category), label: "分类"),
          BottomNavigationBarItem(icon: Icon(Icons.message), label: "消息"),
          BottomNavigationBarItem(icon: Icon(Icons.explore), label: "发现"),
          BottomNavigationBarItem(icon: Icon(Icons.person), label: "我的"),
        ],
      ),
      floatingActionButton: Container(
        height: 80,
        width: 80,
        padding: const EdgeInsets.all(4),
        margin: const EdgeInsets.only(top: 2),
        decoration: BoxDecoration(
            color: Colors.white, borderRadius: BorderRadius.circular(100)),
        child: FloatingActionButton(
          backgroundColor: _currentIndex == 2
              ? Colors.red
              : Theme.of(context).colorScheme.inversePrimary,
          foregroundColor: Colors.white,
          onPressed: () {
            setState(() {
              _currentIndex = 2;
            });
          },
          shape:
              RoundedRectangleBorder(borderRadius: BorderRadius.circular(100)),
          child: const Icon(Icons.add),
        ),
      ),
      floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
    );
  }
}
